package com.rein.study.designpattern.builder._01singleton;

import java.io.ObjectStreamException;
import java.io.Serializable;

public class SerializableSingleton implements Serializable {
    //采用静态变量，类加载的时候就初始化对象
    private static SerializableSingleton instance = new SerializableSingleton();

    //构造函数私有
    private SerializableSingleton() {
    }

    //提供全局访问参数
    private SerializableSingleton getInstance() {
        return instance;
    }

    //重写该方法，保持反序列化一致
    private Object readResolve() throws ObjectStreamException {
        return instance;
    }
}
